import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import path, { resolve } from 'path';

const pathResolve = (dir: string): any => {
  return resolve(__dirname, '.', dir);
};

const alias: Record<string, string> = {
  '@': pathResolve('./src/'),
};

export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
      directoryAsNamespace: true, //解决不同文件夹下命名为Index.vue报命名冲突问题
    }),
  ],
  server: {
    host: '0.0.0.0', //解决vite use--host to expose
    port: 9090,
    open: false, //是否自动打开
    proxy: {
      "/api": {
        // target: "http://vr1a5qj.nat.ipyingshe.com",// 内网穿透外网地址
        target: "http://localhost:8080",// 本地地址
        // target: "http://47.108.93.89:8080",// 线上地址
        // target: "http://47.108.93.89:8085",// 线上地址
        changeOrigin: true,
        rewrite: (path) => path.replace('/api', "")
      }
    }
  },
  resolve: {
    alias,
  },
});
